from django.db.models import  Manager

class UserScoreManager(Manager):
    """用户积分管理器"""
    def __init__(self,extra_model):
        super().__init__()
        self.extra_model = extra_model

    def create_score(self,action,*,user_id,price=1,remark,**kwargs):

        queryset = self.extra_model.objects.filter(action=action, is_delete=False, is_enable=True)

        if queryset.exists():

            score = queryset.first().score * price
            #self.model 获取 UserScore 模型类
            self.model.objects.create(user_id=user_id, score=score, remark=remark,**kwargs)
        return None
